package com.ruoyi.bak.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.bak.domain.BakTaskInfo;
import com.ruoyi.bak.service.IBakTaskInfoService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 数据库备份详情Controller
 * 
 * @author ruoyi
 * @date 2023-01-12
 */
@Controller
@RequestMapping("/bak/info")
public class BakTaskInfoController extends BaseController
{
    private String prefix = "bak/info";

    @Autowired
    private IBakTaskInfoService bakTaskInfoService;

    @RequiresPermissions("bak:info:view")
    @GetMapping()
    public String info()
    {
        return prefix + "/info";
    }

    /**
     * 查询数据库备份详情列表
     */
    @RequiresPermissions("bak:info:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BakTaskInfo bakTaskInfo)
    {
        startPage();
        List<BakTaskInfo> list = bakTaskInfoService.selectBakTaskInfoList(bakTaskInfo);
        return getDataTable(list);
    }

    /**
     * 导出数据库备份详情列表
     */
    @RequiresPermissions("bak:info:export")
    @Log(title = "数据库备份详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BakTaskInfo bakTaskInfo)
    {
        List<BakTaskInfo> list = bakTaskInfoService.selectBakTaskInfoList(bakTaskInfo);
        ExcelUtil<BakTaskInfo> util = new ExcelUtil<BakTaskInfo>(BakTaskInfo.class);
        return util.exportExcel(list, "数据库备份详情数据");
    }

    /**
     * 新增数据库备份详情
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存数据库备份详情
     */
    @RequiresPermissions("bak:info:add")
    @Log(title = "数据库备份详情", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BakTaskInfo bakTaskInfo)
    {
        return toAjax(bakTaskInfoService.insertBakTaskInfo(bakTaskInfo));
    }

    /**
     * 修改数据库备份详情
     */
    @RequiresPermissions("bak:info:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        BakTaskInfo bakTaskInfo = bakTaskInfoService.selectBakTaskInfoById(id);
        mmap.put("bakTaskInfo", bakTaskInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存数据库备份详情
     */
    @RequiresPermissions("bak:info:edit")
    @Log(title = "数据库备份详情", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BakTaskInfo bakTaskInfo)
    {
        return toAjax(bakTaskInfoService.updateBakTaskInfo(bakTaskInfo));
    }

    /**
     * 删除数据库备份详情
     */
    @RequiresPermissions("bak:info:remove")
    @Log(title = "数据库备份详情", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(bakTaskInfoService.deleteBakTaskInfoByIds(ids));
    }
}
